Now let's see how to maintain the heap properties when we modify the heap.

  • The two primary operations are:
    • 1. insert(value): Add a new element to the heap.
    • 2. extractMax(): Remove and return the largest element from the heap.
  • The key challenge is to restore the shape and heap properties after each modification.

Additional Operation

A third common operation is heapify, which efficiently builds a valid heap from an unsorted collection of elements in O(n) time.

100 19 36 17 3 25 101